package LC.demo;

import java.util.Stack;

public class teoDemo {
    public static void main(String[] args) {
        String s = ")(";
        System.out.println(count(s));
    }

    public static boolean isValid(String s) {
        if (s.isEmpty())
            return true;
        Stack<Character> stack = new Stack<Character>();
        for (char c : s.toCharArray()) {
            if (c == '(')
                stack.push(')');
            else if (stack.empty() || c != stack.pop())
                return false;
        }
        if (stack.empty())
            return true;
        return false;
    }

    public static int count(String s) {
        int count = 0;
        if (isValid(s) == true) count++;
        return count;
    }
}
